package com.io.serializable_;

import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.Arrays;

public class JustSerializable {
    public static void main(String[] args) {
        System.out.println("序列化操作");
    }

    @Test
    public void ser()  throws IOException {
        // 序列化
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        try (ObjectOutputStream output = new ObjectOutputStream(buff)) {
            // 写入int
            output.writeInt(100);
            // 写入 String
            output.writeUTF("hello");
            // 写入 Object
            output.writeObject(Double.valueOf(123.456));
        }
        System.out.println(Arrays.toString(buff.toByteArray()));
    }
}
